from rich.console import Console
from rich.table import Table
from rich.panel import Panel
from rich.prompt import Prompt
import datetime

console = Console()

def task_manager():
    tasks = []
    while True:
        console.print(
            Panel.fit("任务管理系统", title_align="center"),
            Panel.fit("1. 添加任务\n2. 查看任务\n3. 删除任务\n4. 退出")
        )
        choice = Prompt.ask("选择操作")
        
        if choice == "1":
            task = {
                "name": Prompt.ask("任务名称"),
                "due": Prompt.ask("截止日期 (YYYY-MM-DD)"),
                "priority": Prompt.ask("优先级 (高/中/低)")
            }
            tasks.append(task)
        elif choice == "2":
            table = Table(title="待办事项")
            for i, t in enumerate(tasks):
                table.add_row(
                    f"{i+1}. {t['name']}",
                    t['due'],
                    t['priority'],
                    "[green]进行中[/green]" if datetime.datetime.now() < datetime.datetime.strptime(t['due'], "%Y-%m-%d") else "[red]已过期[/red]"
                )
            console.print(table)
        elif choice == "3":
            tasks = [t for t in tasks if not Prompt.ask("确认删除？")]

task_manager()